﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication.Admins
{
    public partial class DangKy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public Entities.TaiKhoan GetData()
        {
            Entities.TaiKhoan data = new Entities.TaiKhoan();
            data.TenTaiKhoan = txtTenTaiKhoan.Text;
            data.MatKhau = txtmatkhau.Text;
            data.HoTen = txtHoTen.Text;
            DateTime date;
            date = DateTime.ParseExact(txtNgaySinh.Text, "dd/MM/yyyy", null);
            data.NgaySinh = date;
            if (rdNam.Checked == true)
                data.GioiTinh = 1;
            else
                if (rdNu.Checked == true)
                    data.GioiTinh = 0;
                else
                    if (rdNo.Checked == true)
                        data.GioiTinh = -1;
            data.Email = txtEmail.Text;
            return data;
        }



        protected void txtDangKy_Click1(object sender, EventArgs e)
        {

        }

        protected void btnDangKyTT_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                bool rs = false;
                Entities.TaiKhoan data = GetData();
                if (data.IDTaiKhoan > 0)
                {
                    lblThongBao.Text = "\t Đăng ký không thành công";
                }
                else
                {
                    rs = BLL.TaiKhoanBLL.DangKy(data);
                    lblThongBao.Text = "\t Đăng ký thành công";
                    if(rs)
                        resert();
                }


            }
        }

        protected void btnMacDinh_Click(object sender, EventArgs e)
        {
            resert();

        }

        private void resert()
        {
            txtTenTaiKhoan.Text = "";
            txtmatkhau.Text = "";
            txtMatKhau2.Text = "";
            txtNgaySinh.Text = "";
            txtHoTen.Text = "";
            rdNam.Checked = true;
            rdNu.Checked = false;
            rdNo.Checked = false;
            txtEmail.Text = "";
            txtEmail2.Text = "";
        }

        protected void UpdateTimer_Tick(object sender, EventArgs e)
        {
          
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
           
        }
    }
}